<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file='public/_meta' /}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" name="submitform" id="submitform">
            <div class="layui-form-item">
                <label for="menu_id" class="layui-form-label">
                    <span class="x-red">*</span>所属菜单
                </label>
                <div class="layui-input-inline">
                    <select name="menu_id" id="menu_id" lay-filter="selectchange">
                        {foreach $menus as $k=>$v}
                        <option value="{$v.id}" {if $info.menu_id==$v.id}selected{/if} >{$v.title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="pid" class="layui-form-label">
                    <span class="x-red">*</span>上级权限
                </label>
                <div class="layui-input-inline">
                    <select name="pid" id="pid" lay-filter="class" >
                        <option value="0">顶级权限</option>
                        {foreach $plist as $k=>$v}
                        <option value="{$v.id}" {if $info.pid==$v.id}selected{/if} >|--{$v.title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="title" class="layui-form-label">
                    <span class="x-red">*</span>权限标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title" name="title" value="{$info.title}" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="auth" class="layui-form-label">
                    <span class="x-red">*</span>权限规则
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="auth" name="auth" value="{$info.auth}" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="is_menu1" class="layui-form-label">
                    <span class="x-red">*</span>是否菜单
                </label>
                <div class="layui-input-inline">
                    <input type="radio" name="is_menu" id="is_menu1" value="1" title="是" {if $info.is_menu=='是'}checked="true"{/if} >
                    <input type="radio" name="is_menu" id="is_menu2" value="0" title="否" {if $info.is_menu=='否'}checked="true"{/if} >
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        //监听提交
        form.on('submit(add)',
            function(data) {
                //发异步，把数据提交给php
                var formdata = {
                    'menu_id': data.field.menu_id,
                    'is_menu' : data.field.is_menu,
                    'auth' : data.field.auth,
                    'pid' : data.field.pid,
                    'title' : data.field.title,
                    'id' : "{$info.id}"
                };

                //console.log(formdata);
                $.getJSON("{:url('admin/auth/editdo')}",formdata,function(res){

                    if(parseInt(res.statusCode)==200){
                        layer.alert(res.message, {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            }
                        );
                    }else{
                        layer.message(res.message);
                    }
                });

                return false;
            });

        /*form.on('select(selectchange)', function(data){
            var html = '';
            html += "<option value='0'>顶级权限</option>";
            $.post("{:url('admin/auth/add')}",{'mid':data.value},function(res){
                var jdata = JSON.parse(res);
                $.each(jdata,function(i,item){
                    //console.log(item.id);
                    html += "<option value='"+item.id+"'>|--"+item.title+"</option>";
                })
            })
            document.getElementById('pid').innerHTML = html;
        });*/

        /*form.render('select', 'selectchange');*/

    });
</script>

</body>

</html>
